﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Core;
using System.Data;

namespace DAL
{
  public  class Quan_HuyenDAL
    {
      public static List<Quan_Huyen> LayTatCa()
      {
          try
          {
              return CBO.FillCollection<Quan_Huyen>(DataProvider.Instance.ExecuteReader("Quan_Huyen_LayTatCa"));
          }
          catch
          {

              return new List<Quan_Huyen>();
          }
      }
      public static bool Them(Quan_Huyen qh)
      {
          try
          {
              object rs = DataProvider.Instance.ExecuteNonQueryWithOutput("@IDQuanHuyen", "Quan_Huyen_Them", qh.IDQuanHuyen,qh.TenQuanHuyen, qh.MoTa, qh.IDTinhTP);
              return Convert.ToInt32(rs) > 0;

          }
          catch
          {

              return false;
          }
      }
      public static bool Sua(Quan_Huyen qh)
      {
          try
          {
              int rs = DataProvider.Instance.ExecuteNonQuery("Quan_Huyen_Sua", qh.IDQuanHuyen, qh.TenQuanHuyen, qh.MoTa, qh.IDTinhTP);
              return Convert.ToInt32(rs) > 0;
          }
          catch
          {

              return false;
          }

      }
     
      public static bool Xoa(string ID)
      {
          try
          {
              int rs = DataProvider.Instance.ExecuteNonQuery("QuanHuyen_Xoa", Convert.ToInt32(ID));
              return Convert.ToInt32(rs) > 0;

          }
          catch
          {

              return false;
          }
      }
      public static Quan_Huyen LayID(string IdQuanHuyen)
      {
          try
          {
              return CBO.FillObject<Quan_Huyen>(DataProvider.Instance.ExecuteReader("Quan_Huyen_LayID", Convert.ToInt32(IdQuanHuyen)));
          }
          catch
          {
              return null;
          }
      }
      public static List<Quan_Huyen> TimKiemTen(string Ten)
      {
          try
          {
              return CBO.FillCollection<Quan_Huyen>(DataProvider.Instance.ExecuteReader("Quan_Huyen_TimKiemTenQH", Ten));

          }
          catch
          {

              return new List<Quan_Huyen>();
          }
      }
      //public static List<Quan_Huyen> Paging(string page, out int howManyPages)
      //{
      //    IDataReader reader = null;
      //    try
      //    {
      //        int pageSize = GlobalConfiguration.PageSize;
      //        reader = DataProvider.Instance.ExecuteReader(
      //             "QuanHuyen_Paging",
      //             page,
      //             GlobalConfiguration.PageSize);
      //        reader.Read();
      //        howManyPages = (int)Math.Ceiling((double)reader.GetInt32(0) /
      //(double)pageSize);

      //        reader.NextResult();
      //        return CBO.FillCollection<Quan_Huyen>(reader);
      //    }
      //    catch
      //    {
      //        if (reader != null && reader.IsClosed == false)
      //            reader.Close();
      //        howManyPages = 0;
      //        return new List<Quan_Huyen>();
      //    }
      //}
    }

}
